# @Time : 2023/1/5
# @Author : SDAJAVA

import urllib.request
import urllib.parse
import json

url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'

headers = {
    'Accept': '*/*',
    # 'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Acs-Token': '1672819565790_1672903498719_IRY41jkYH25xf5fk0eHbI6toZGqEmt1sybw3hdZMkAUd8DfgUBuW4u3x3XIh2cSnIsXoAZeEe7bI1fnDggD6x3eHYbOq5k7W82RqiQHEiyvU2NZL5YecZ8Q6ib64g/V7CjD+KQvWAZAVYFbBLSZlharpsr5bXbCAeHmXTpIjfsatiO2cD4Sbl/omTJmpBof+YDEVuCuYIdVNUQWhhguq1+AaAIqgFBxm0gVqul0sskv7RmaO9AYQNBo1ygyM3Xs6vASxWYxEMiFPjPzLoTPROMy/ggQVSoSPJSXyi8XJJRLlrX4chvWmYnq4wiYz6cEG',
    'Connection': 'keep-alive',
    'Content-Length': '135',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    # 主要关键点
    'Cookie': '__yjs_duid=1_6aed299efaf6c7ad57089a16af24728f1633742399494; X-baiduvr-auth-token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJkM2ZiODZiNjRjYjk0MDdlYTdkODBlNWJhMzZiYjY2OSIsInZyLXN5c3RlbS1pZCI6InN5cy12ci1tdnAiLCJ2ci1hY2NvdW50LWlkIjoiZDNmYjg2YjY0Y2I5NDA3ZWE3ZDgwZTViYTM2YmI2NjkiLCJ2ci11c2VyLWlkIjoiZDNmYjg2YjY0Y2I5NDA3ZWE3ZDgwZTViYTM2YmI2NjkiLCJ2ci1hY2NvdW50LXR5cGUiOjEsInZyLXVzZXItdHlwZSI6MSwiaXNzIjoiQkFJRFUtVlIiLCJpYXQiOjE2Mzk3MTIyMzEsImF1ZCI6ImN1c3RvbSIsImV4cCI6MTY0NDg5NjIzMX0.9dVsrtJshbZsZjrtwhJdtafc4Bh-R3LvBQiOIkVHugw; vr-system-id=sys-vr-mvp; vr-account-id=d3fb86b64cb9407ea7d80e5ba36bb669; vr-user-id=d3fb86b64cb9407ea7d80e5ba36bb669; vr-account-type=1; vr-user-type=1; BDUSS=dUZEVPTFJpME04Q3REaUtnV0hxWkZaY1F2SGtDRmtCdmFsc1RXNFcxMG8yb3BqRUFBQUFBJCQAAAAAAAAAAAEAAACP2z0Xc2RhamF2YQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAChNY2MoTWNjSn; BDUSS_BFESS=dUZEVPTFJpME04Q3REaUtnV0hxWkZaY1F2SGtDRmtCdmFsc1RXNFcxMG8yb3BqRUFBQUFBJCQAAAAAAAAAAAEAAACP2z0Xc2RhamF2YQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAChNY2MoTWNjSn; APPGUIDE_10_0_2=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; BIDUPSID=A1FCEC6C8FD0B1F7EED3FAFE291AACB0; PSTM=1670466432; H_WISE_SIDS=131861_188748_204910_204947_211986_213046_213358_214801_215727_216843_219559_219623_219942_219946_222216_222624_223064_223323_224436_226628_227870_227932_228650_229154_229967_230288_230930_231979_232357_232777_232959_234044_234295_234306_234426_234436_234725_234784_235174_235442_235512_235714_235980_236239_236242_236516_236536_236611_236653_236810_237342_237362_237448_237807_237821_237836_237892_237964_238072_238144_238148_238226_238267_238313_238507_238511_238629_238756_238981_239006_239102_239118_239281_239397_239604_239704_239761_239898_239947_239963_240015_240035_240226_240306_240368_240407_240447_240465_240594_240598_240650_240663_240724_240729_240745_240782_240890_240905_241044_241178_241208_241231_241297_241382_241567_241715; H_WISE_SIDS_BFESS=131861_188748_204910_204947_211986_213046_213358_214801_215727_216843_219559_219623_219942_219946_222216_222624_223064_223323_224436_226628_227870_227932_228650_229154_229967_230288_230930_231979_232357_232777_232959_234044_234295_234306_234426_234436_234725_234784_235174_235442_235512_235714_235980_236239_236242_236516_236536_236611_236653_236810_237342_237362_237448_237807_237821_237836_237892_237964_238072_238144_238148_238226_238267_238313_238507_238511_238629_238756_238981_239006_239102_239118_239281_239397_239604_239704_239761_239898_239947_239963_240015_240035_240226_240306_240368_240407_240447_240465_240594_240598_240650_240663_240724_240729_240745_240782_240890_240905_241044_241178_241208_241231_241297_241382_241567_241715; BAIDUID=37F74FA349F0F242A0281524F8542F5F:SL=0:NR=10:FG=1; newlogin=1; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; MCITY=-233%3A; BAIDUID_BFESS=37F74FA349F0F242A0281524F8542F5F:SL=0:NR=10:FG=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; delPer=0; PSINO=7; BA_HECTOR=2l84042k258l818h0h2la2u21hrcseb1j; ZFY=IXuTONBZIwLhKJLCAaALPz3ClVJXFXW5kmbw3Mc8I3w:C; H_PS_PSSID=36543_37972_37557_37521_37906_36920_37989_37802_36805_37927_38041_26350_37881; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1670717348,1672033442,1672213634,1672903473; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1672903478; ab_sr=1.0.1_M2M4ZDI5ZDc2MDY3YjExYjE2NzBjNzgwMTQwNzA5ZmY3NjQ0N2VhNGYzMmU3ZGM1MGQxZDE0NzQ2NWYxMGFlZjE4OTk3MjRiZDU1ZDJjNTUxNThlZjQ1OTIwYTA2YjhkZmVhYjY4MjAyMTMzMGUwMDI0NDU4ZjdjODk5NDdjMGIzNDgzZGMyMWIzNjM5Nzk1YjNmMGIxNDE1YjVhY2ZmOWI4M2E3NTE2ODFlZTU2YmExOTk4ZWM5NTNjYzc3NjY0',
    'Host': 'fanyi.baidu.com',
    'Origin': 'https://fanyi.baidu.com',
    'Referer': 'https://fanyi.baidu.com/',
    'sec-ch-ua': '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
}

data = {
    'from': 'en',
    'to': 'zh',
    'query': 'love',
    'transtype': 'realtime',
    'simple_means_flag': '3',
    'sign': '198772.518981',
    'token': '6e23cfa048a6606d08cf9a45f1b5a683',
    'domain': 'common',
}

data = urllib.parse.urlencode(data).encode('utf-8')

request = urllib.request.Request(url=url, data=data, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

print(json.loads(content))